package char

import (
	"fmt"
	//"container/list"
	"code.google.com/p/my-little-rpg/goMyLittleRPG/dice"
)

type Character struct {
	level int
	name  string
	str   int
	dex   int
	con   int
	intel int
	wis   int
	cha   int
}

func New(name string) *Character {
	v := generateRandomAttributes()
	return &Character{
		level: 1,
		name:  name,
		str:   v[0],
		dex:   v[1],
		con:   v[2],
		intel: v[3],
		wis:   v[4],
		cha:   v[5],
	}
}

func (c *Character) Name() string {
	return c.name
}

func (c *Character) PrintCharacterSheet() {
	fmt.Println("Level: ", c.level)
	fmt.Println("Name: ", c.name)
	fmt.Println("STR: ", c.str)
	fmt.Println("DEX: ", c.dex)
	fmt.Println("CON: ", c.con)
	fmt.Println("INT: ", c.intel)
	fmt.Println("WIS: ", c.wis)
	fmt.Println("CHA: ", c.cha)

}

func generateRandomAttributes() []int {
	attributes := make([]int, 6)
	atr := 0
	rolls := make([]int, 4)
	position := 0
	d6 := dice.New(6)
	for i := 0; i < 6; i++ {
		for k := 0; k < 4; k++ {
			rolls[k] = d6.Roll()
		}
		min := rolls[0]
		position = 0
		for j := 1; j < 4; j++ {
			if rolls[j] < min {
				min = rolls[j]
				position = j
			}
		}
		atr = 0
		for z := 0; z < 4; z++ {
			if z != position {
				atr += rolls[z]
			}
		}
		attributes[i] = atr
	}
	return attributes

}

/*func main() {
	c := New("Mike")
	c.PrintCharacterSheet()
}*/
